﻿//
// Copyright (c) 2024 BPer
//

#ifndef BPERUTIL_BPERAVINFOTYPE_H_
#define BPERUTIL_BPERAVINFOTYPE_H_
#include <bperutil/BPerType.h>
#include <bperutil/BPerAvType.h>


typedef struct BPerAudioInfo {
	int32_t sample;
	int32_t frameSize;
	int32_t bitrate;
	int32_t channel;

	BPerBool enableMono;
	BPerBool enableAec;
	int32_t echoPath;

	BPerBool enableAudioFec;

	int32_t aecBufferFrames;
	int32_t audioCacheSize;
	int32_t audioCacheNum;
	int32_t audioPlayCacheNum;

	BPerBool enableAudioHeader;
	int32_t audioEncoderType;
	int32_t audioDecoderType;
	int32_t audioPlayType;

	int32_t aIndex;
	int32_t aSubIndex;
}BPerAudioInfo;

typedef struct BPerVideoInfo {
	int32_t width; //= 800
	int32_t height; //= 600
	int32_t outWidth;
	int32_t outHeight;
	int32_t rate; // 512
	int32_t frame; //25
	int32_t rotate; // 16
	int32_t bitDepth;

	int32_t videoCacheNum;
	int32_t evideoCacheNum;
	int32_t videoPlayCacheNum;

	BPerColorSpace videoCaptureFormat;
	BPerColorSpace videoEncoderFormat;
	BPerColorSpace videoDecoderFormat;

	int32_t videoEncoderType;
	int32_t videoDecoderType;
	int32_t videoEncHwType;
	int32_t videoDecHwType;
	int32_t vIndex;
}BPerVideoInfo;

typedef struct BPerVideoEncInfo {
	int32_t preset;
	int32_t level_idc;
	int32_t profile;
	int32_t keyint_max;
	int32_t enc_threads;
	int32_t gop;
	BPerBool createMeta;
}BPerVideoEncInfo;

typedef struct BPerSysInfo {
	BPerIpFamilyType familyType;
	BPerBool enableLogFile;
	int32_t mediaServer;
	int32_t httpPort;
	int32_t transType;
	int32_t logLevel;
	char whipUrl[128];
	char whepUrl[128];
}BPerSysInfo;

typedef struct BPerRtcInfo {
	BPerBool enableHttpServerSdp;

	int32_t sessionTimeout;
        //BPerBool enableDatachannel;
	int32_t iceCandidateType;
	BPerBool iceUsingLocalIp;
	int32_t iceServerPort;
	BPerBool enableAudioBuffer;
	int32_t rtcSocketProtocol;
	int32_t turnSocketProtocol;

	int32_t rtcPort;
	int32_t rtcLocalPort;

	char localIp[32];
	char rtcServerIP[32];

	char iceServerIP[64];
	char iceLocalIP[64];
	char iceUserName[32];
	char icePassword[64];
}BPerRtcInfo;

typedef struct BPerAVInfo{
	BPerSysInfo sys;
	BPerAudioInfo audio;
	BPerVideoInfo video;
	BPerVideoEncInfo enc;
	BPerRtcInfo rtc;
}BPerAVInfo;


#ifdef __cplusplus
#include <bperstream/BPerStreamManager.h>
#include <bperstream/BPerSynBufferManager.h>
class BPerContext {
public:
	BPerContext();
	virtual ~BPerContext();
	void init(char *filename);
	void init();

	virtual void initExt(void *filename);
	virtual void initExt();
public:

	BPerAVInfo avinfo;
	BPerRtcCallback rtcCallback;
	BPerSendRtcMessage sendRtcMessage;

#if BPer_OS_ANDROID
	void* nativeWindow;
#endif

        BPerSynBufferManager synMgr;
        BPerStreamManager* streams;
};
extern "C"{
void bPer_init_avinfo(BPerAVInfo* avinfo);
}
#else
void bPer_init_avinfo(BPerAVInfo* avinfo);
#endif

#endif /* BPERUTIL_BPERTYPE_H_ */
